package com.dsj.gxrd.modules.controller.book;

import java.util.List;

import com.dsj.gxrd.modules.book.domain.dto.RdBookDto;
import com.dsj.gxrd.modules.book.domain.dto.RdCommShareDto;
import com.dsj.gxrd.modules.book.domain.groups.Group03;
import com.dsj.gxrd.modules.book.domain.query.RdBookQuery;
import com.dsj.gxrd.modules.book.mapper.RdBookMapper;
import com.dsj.gxrd.modules.book.service.IRdBookService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 *
 * @author ruoyi
 * @date 2023-09-11
 */
@Api(tags = "书香人大推荐书籍")
@RestController
@RequestMapping("/book")
public class RdBookController extends BaseController
{
    @Autowired
    private IRdBookService rdBookService;

    @Autowired
    private RdBookMapper rdBookMapper;

    @RequiresPermissions("book:book:list")
    @GetMapping("/list")
    public TableDataInfo list(RdBookQuery rdBook)
    {
        startPage();
        List<RdBookDto> list = rdBookService.selectRdBookList(rdBook);
        return getDataTable(list);
    }


    @RequiresPermissions("book:book:query")
    @GetMapping(value = "/{rdBookId}")
    public AjaxResult getInfo(@PathVariable("rdBookId") Long rdBookId)
    {
        return success(rdBookService.selectRdBookByRdBookId(rdBookId));
    }


    @RequiresPermissions("book:book:add")
    @Log(title = "【新增书籍】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RdBookDto rdBook)
    {
        return toAjax(rdBookService.insertRdBook(rdBook));
    }


    @RequiresPermissions("book:book:edit")
    @Log(title = "【修改书籍】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RdBookDto rdBook)
    {
        return toAjax(rdBookService.updateRdBook(rdBook));
    }


    @RequiresPermissions("book:book:remove")
    @Log(title = "【删除书籍】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{rdBookIds}")
    public AjaxResult remove(@PathVariable List<Long> rdBookIds)
    {
        return toAjax(rdBookService.deleteRdBookByRdBookIds(rdBookIds));
    }

    @RequiresPermissions("book:book:approval")
    @PostMapping("/approval")
    public AjaxResult approval(@RequestBody RdBookDto rdBook)
    {
        return toAjax(rdBookService.approval(rdBook));
    }

}
